package com.mystnihon.freeremote.loader.torrent;

import android.util.Log;
import ca.benow.transmission.TransmissionClient;

import com.mystnihon.freeremote.config.Config;
import com.octo.android.robospice.request.SpiceRequest;

/**
 * SpiceRequest to proceeed to the reannounce of a list of torrent if specified, or to the reannounce of the recently-active torrent if not.
 * 
 * @author Utilisateur Niji
 */
public class ReannounceTorrentRequest extends SpiceRequest<Void> {

    private static final String TAG = ReannounceTorrentRequest.class.getSimpleName();
    private TransmissionClient mclient;
    private Object[] mIds;

    public ReannounceTorrentRequest(TransmissionClient client, Object... ids) {
        super(Void.class);
        mclient = client;
        mIds = ids;
    }

    @Override
    public Void loadDataFromNetwork() throws Exception {
        if (Config.DEBUG_MODE_ENABLED)
            Log.d(TAG, "Reannounce recently active torrents");
        if (mIds.length > 0) {
            mclient.reannounceTorrents(mIds);
        } else {
            mclient.reannounceRecentlyActiveTorrents();
        }
        return null;
    }

}
